<template>
  <div class="app-container customer-div">
    <el-tabs v-model="activeName" style="margin-top:20px;" type="card">
      <el-tab-pane label="我的" name="my">
        <el-button size="small" @click="getList" type="primary">刷新</el-button>
        <!--数据列表-->
        <el-table
          height="400"
          v-loading="listLoading"
          :data="tableData"
          border
          style="width: 100%; margin-top: 20px">
          <el-table-column
            label="姓名"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.userName}}
            </template>
          </el-table-column>
          <el-table-column
            label="月份"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.month}}
            </template>
          </el-table-column>
          <el-table-column
            label="基准目标量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.standard}}
            </template>
          </el-table-column>
          <el-table-column
            label="交接量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.additional}}
            </template>
          </el-table-column>
          <el-table-column
            min-width="100"
            align="center">
            <template slot="header" slot-scope="scope">
              <div>基本目标量<br/>(基准量+交接量)</div>
            </template>
            <template slot-scope="scope">
              {{scope.row.minVolume}}
            </template>
          </el-table-column>
          <el-table-column
            label="个人目标量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.targetVolume}}
            </template>
          </el-table-column>
          <el-table-column
            label="实际完成量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.volume}}
            </template>
          </el-table-column>
          <el-table-column
            label="基本比例"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.percentAge}}
            </template>
          </el-table-column>
          <el-table-column
            label="提成系数"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.royaltyRatio}}
            </template>
          </el-table-column>
          <el-table-column
            min-width="100"
            align="center">
            <template slot="header" slot-scope="scope">
                <div>总提成比例<br/>(基本系数+提成系数)</div>
            </template>
            <template slot-scope="scope">
              {{scope.row.finishedRatio}}
            </template>
          </el-table-column>
          <el-table-column
            label="实际完成量/个人目标量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.actualAuth}}
            </template>
          </el-table-column>
          <el-table-column
            label="实际完成量/基本目标量"
            min-width="100"
            align="center">
            <template slot-scope="scope">
              {{scope.row.actualStandard}}
            </template>
          </el-table-column>

        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :current-page.sync="listQuery.pageNum"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :total="count">
          </el-pagination>
        </div>

      </el-tab-pane>
      <el-tab-pane label="军团" v-if="growthAnalysisTeam" name="team">
        <div style="margin-top: 20px">
          <!--搜索-->
          <el-form :inline="true"  size="mini" label-width="180px">
            <el-form-item label="业务员（一次最多选6人）：">
              <el-select v-model="listQuery2.userIds" filterable placeholder="请选择" clearable multiple  :multiple-limit="6" style="width:440px;">
                <el-option
                  v-for="item in userOptionList2"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                @click="handleSearchList2"
                type="primary">
                查询
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <!--数据列表-->
        <div class="table-container">
                <!--数据列表-->
                <el-table
                  height="400"
                  v-loading="listLoading2"
                  :data="tableData2"
                  border
                  style="width: 100%; margin-top: 20px">
                  <el-table-column
                    label="姓名"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.userName}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="月份"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.month}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="基准目标量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.standard}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="交接量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.additional}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    min-width="100"
                    align="center">
                    <template slot="header" slot-scope="scope">
                      <div>基本目标量<br/>(基准量+交接量)</div>
                    </template>
                    <template slot-scope="scope">
                      {{scope.row.minVolume}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="个人目标量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.targetVolume}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="实际完成量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.volume}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="基本比例"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.percentAge}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="提成系数"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.royaltyRatio}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    min-width="100"
                    align="center">
                    <template slot="header" slot-scope="scope">
                      <div>总提成比例<br/>(基本系数+提成系数)</div>
                    </template>
                    <template slot-scope="scope">
                      {{scope.row.finishedRatio}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="实际完成量/个人目标量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.actualAuth}}
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="实际完成量/基本目标量"
                    min-width="100"
                    align="center">
                    <template slot-scope="scope">
                      {{scope.row.actualStandard}}
                    </template>
                  </el-table-column>
                </el-table>
                <div class="pagination-container">
                  <el-pagination
                    background
                    @size-change="handleSizeChange2"
                    @current-change="handleCurrentChange2"
                    layout="total, sizes,prev, pager, next,jumper"
                    :current-page.sync="listQuery2.pageNum"
                    :page-size="listQuery2.pageSize"
                    :page-sizes="[10,15,20]"
                    :total="count2">
                  </el-pagination>
                </div>
        </div>

      </el-tab-pane>
      <el-tab-pane label="全部" v-if="growthAnalysisAll" name="all">
        <div style="margin-top: 20px">
          <!--搜索-->
          <el-form :inline="true"  size="mini" label-width="180px">
            <el-form-item label="业务员（一次最多选6人）：">
              <el-select v-model="listQuery3.userIds" filterable placeholder="请选择" clearable multiple  :multiple-limit="6" style="width:440px;">
                <el-option
                  v-for="item in userOptionList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                @click="handleSearchList3"
                type="primary">
                查询
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <!--数据列表-->
        <div class="table-container">
                 <!--数据列表-->
                 <el-table
                   height="400"
                   v-loading="listLoading3"
                   :data="tableData3"
                   border
                   style="width: 100%; margin-top: 20px">
                   <el-table-column
                     label="姓名"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.userName}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="月份"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.month}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="基准目标量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.standard}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="交接量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.additional}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     min-width="100"
                     align="center">
                     <template slot="header" slot-scope="scope">
                       <div>基本目标量<br/>(基准量+交接量)</div>
                     </template>
                     <template slot-scope="scope">
                       {{scope.row.minVolume}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="个人目标量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.targetVolume}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="实际完成量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.volume}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="基本比例"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.percentAge}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="提成系数"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.royaltyRatio}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     min-width="100"
                     align="center">
                     <template slot="header" slot-scope="scope">
                       <div>总提成比例<br/>(基本系数+提成系数)</div>
                     </template>
                     <template slot-scope="scope">
                       {{scope.row.finishedRatio}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="实际完成量/个人目标量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.actualAuth}}
                     </template>
                   </el-table-column>
                   <el-table-column
                     label="实际完成量/基本目标量"
                     min-width="100"
                     align="center">
                     <template slot-scope="scope">
                       {{scope.row.actualStandard}}
                     </template>
                   </el-table-column>
                 </el-table>
                 <div class="pagination-container">
                   <el-pagination
                     background
                     @size-change="handleSizeChange3"
                     @current-change="handleCurrentChange3"
                     layout="total, sizes,prev, pager, next,jumper"
                     :current-page.sync="listQuery3.pageNum"
                     :page-size="listQuery3.pageSize"
                     :page-sizes="[10,15,20]"
                     :total="count3">
                   </el-pagination>
                 </div>
        </div>

      </el-tab-pane>
      <el-tab-pane label="基准线设置" v-if="benchmark" name="benchmark">
        <div style="margin-top: 20px">
          <!--搜索-->
          <el-form :inline="true" :model="listQuery4" size="mini" label-width="80px">
            <el-form-item label="产品线：">
              <el-select v-model="listQuery4.goodsLineId" clearable>
                <el-option :label="item.cddValue" v-for="item in goodsLineList" :value="item.cddId" :key="item.cddId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                @click="handleSearchList4()"
                type="primary">
                查询
              </el-button>
              <el-button
                @click="showImport2"
                type="primary">
                批量导入
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <!--数据列表-->
        <div class="table-container">
          <el-table
            v-loading="listLoading4"
            :data="tableData4"
            border
            style="width: 100%; margin-top: 20px">
            <el-table-column
              label="月份"
              min-width="100"
              align="center">
              <template slot-scope="scope">
                第{{ scope.row.month}}个月
              </template>
            </el-table-column>
            <el-table-column
              label="基准量"
              min-width="100"
              align="center">
              <template slot-scope="scope" >
                {{ scope.row.standard}}
              </template>
            </el-table-column>
            <el-table-column label="产品线" align="center"  min-width="100">
              <template slot-scope="scope" >
                {{ scope.row.goodsLine}}
              </template>
            </el-table-column>
            <el-table-column
              label="更新时间"
              min-width="150"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.updateTime}}
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              min-width="100"
              align="center">
              <template slot-scope="scope">
                  <el-button type="text" @click="showPop2('edit',scope.row)">修改</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
              background
              @size-change="handleSizeChange4"
              @current-change="handleCurrentChange4"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery4.pageNum"
              :page-size="listQuery4.pageSize"
              :page-sizes="[10,15,20]"
              :total="count4">
            </el-pagination>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="交接量设置" v-if="additional" name="additional">
        <div style="margin-top: 20px">
          <!--搜索-->
          <el-form :inline="true" :model="listQuery5" size="mini" label-width="80px">
            <el-form-item label="员工姓名：">
              <el-select v-model="listQuery5.userId" filterable placeholder="请选择" clearable>
                <el-option
                  v-for="item in userOptionList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                @click="handleSearchList5()"
                type="primary">
                查询
              </el-button>
              <el-button
                @click="showPop('add','')"
                type="primary">
                新增
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <!--数据列表-->
        <div class="table-container">
          <el-table
            v-loading="listLoading5"
            :data="tableData5"
            border
            style="width: 100%; margin-top: 20px">
            <el-table-column
              label="月份"
              min-width="100"
              align="center">
              <template slot-scope="scope">
                第{{ scope.row.month}}个月
              </template>
            </el-table-column>
            <el-table-column
              label="员工姓名"
              min-width="100"
              align="center">
              <template slot-scope="scope" >
                {{ scope.row.userName}}
              </template>
            </el-table-column>
            <el-table-column label="交接量" align="center"  min-width="100">
              <template slot-scope="scope" >
                {{ scope.row.additional}}
              </template>
            </el-table-column>
            <el-table-column
              label="更新时间"
              min-width="150"
              align="center">
              <template slot-scope="scope">
                {{ scope.row.updateTime}}
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              min-width="100"
              align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="showPop('edit',scope.row)">修改</el-button>
                <el-button type="text" @click="delItem(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
              background
              @size-change="handleSizeChange5"
              @current-change="handleCurrentChange5"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery5.pageNum"
              :page-size="listQuery5.pageSize"
              :page-sizes="[10,15,20]"
              :total="count5">
            </el-pagination>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>

    <!--新增交接量-->
    <el-dialog
      :close-on-click-modal="false"
      title="交接量设置"
      :visible.sync="dialogVisible"
      width="350px">
      <el-form :model="form" size="mini" label-width="100px" ref="form" :rules="rules">
        <el-form-item label="月份：" prop="month">
            <el-input-number :min="1" controls-position="right" v-model="form.month"></el-input-number>
        </el-form-item>
        <el-form-item label="员工姓名：" prop="userId">
          <el-select v-model="form.userId" filterable placeholder="请选择" clearable style="width:130px">
            <el-option
              v-for="item in userOptionList"
              :key="item.userId"
              :label="item.name"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交接量：" prop="additional">
          <el-input-number controls-position="right"  v-model="form.additional"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 定</el-button>
      </span>
    </el-dialog>

    <!--基准量-->
    <el-dialog
      :close-on-click-modal="false"
      title="基准量设置"
      :visible.sync="dialogVisible2"
      width="350px">
      <el-form :model="form2" size="mini" label-width="100px" ref="form2" :rules="rules2">
        <el-form-item label="月份：" prop="month">
          <el-input-number :min="1" controls-position="right" v-model="form2.month"></el-input-number>
        </el-form-item>
        <el-form-item label="产品线：" prop="goodsLineId">
          <el-select v-model="form2.goodsLineId" clearable style="width:130px">
            <el-option :label="item.cddValue" v-for="item in goodsLineList" :value="item.cddId" :key="item.cddId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="基准量：" prop="standard">
          <el-input-number controls-position="right" :min="0" v-model="form2.standard"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose2">取 消</el-button>
          <el-button type="primary" @click="handleConfirm2" :loading="btnLoading2">确 定</el-button>
      </span>
    </el-dialog>

    <!--导入-->
    <el-dialog
      :show-close="showClose2"
      :close-on-click-modal="showClose2"
      :close-on-press-escape="showClose2"
      title="批量导入"
      :beforeClose="beforeCloseEditPrice2"
      :visible.sync="dialogVisibleImprot2"
      width="500px">
      <div>
        <el-alert
          title="请先下载模板，维护后，再上传更新后的模板文件"
          type="warning"
          :closable="false">
        </el-alert>
        <div style="text-align: center;padding:20px;padding-bottom:10px">
          <el-link :href="url" type="primary" :underline="false">下载模板</el-link>
        </div>
        <div class="upload-div" style="margin-top:20px">
          <input id="upload" type="file" @change="importfxx(this)" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
          <el-button type="primary" size="small" :loading="uploadLoading">选择上传文件</el-button>
        </div>
        <div style="margin:20px auto;margin-bottom:0;word-break:break-all;text-align: left;line-height:20px;background: #fef0f0;color:#f56c6c;padding:10px" v-if="msg2!=''">
          <div style="max-height: 90px;overflow: auto;padding:10px"><div v-if="showFial2">添加失败：</div>{{msg2}}</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="handleEditPriceConfirm2" :loading="EditLoading2">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {getDepartmentUser,importStandard,getCustomerSetting,getOrderUsersList,addStandard,saleAnalysisList,addAdditional,getAdditionalList,getStandardList,delAdditional} from '@/api/partner'
import {getTargetVolumeList} from '@/api/order'
import {goodsList} from '@/api/company'
import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import XLSX from "xlsx";
const defaultListQuery={
  "userIds" : [],  //业务员ID
  "pageNum" : 1,
  "pageSize" : 10
};

const defaultListQuery4={
  goodsLineId:'',
  "pageNum" : 1,
  "pageSize" : 10
};

const defaultListQuery5={
  userId:'',
  "pageNum" : 1,
  "pageSize" : 10
};

const defaultForm={
  "usaId" : 0, //交接量 ID，为0时表示新增，否则编辑
  "month" :'',  //月份
  "userId"  : '', //员工
  "additional" : "", //交接量
}

const defaultForm2={
  "ussId" : 0, //交接量 ID，为0时表示新增，否则编辑
  "month" :'',  //月份
  "goodsLineId"  : '', //产品线
  "standard" : "", //基准量
}

const defaultItem={
  userId:'',
  userName:'',
  pageNum:1,
  pageSize:10,
  count:0,
  tableData:[],
  listLoading:false
}


export default {
  name: "index",
  data(){
    return {
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData: [],
      listLoading: false,

      listQuery2: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData2: [],
      listLoading2: false,
      count2:0,

      listQuery3: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData3: [],
      listLoading3: false,
      count3:0,


      roles:store.getters.roles ? store.getters.roles : [],
      loading:false,
      count:0,
      activeName:'my',


      userIds:[],
      userList:[],

      userIds2:[],
      userList2:[],

      listQuery4: JSON.parse(JSON.stringify(defaultListQuery4)),
      tableData4: [{},{}],
      listLoading4: false,
      count4:0,

      listQuery5: JSON.parse(JSON.stringify(defaultListQuery5)),
      tableData5: [{},{}],
      listLoading5: false,
      count5:0,
      userOptionList:[],
      tab:'my',
      dialogVisible:false,
      form:JSON.parse(JSON.stringify(defaultForm)),
      btnLoading:false,
      rules:{
        month:[{required: true, message: '此项必填', trigger: 'blur'},],
        userId:[{required: true, message: '此项必填', trigger: 'change'},],
        additional:[{required: true, message: '此项必填', trigger: 'blur'},],
      },
      dialogVisible2:false,
      form2:JSON.parse(JSON.stringify(defaultForm2)),
      btnLoading2:false,
      rules2:{
        month:[{required: true, message: '此项必填', trigger: 'blur'},],
        goodsLineId:[{required: true, message: '此项必填', trigger: 'change'},],
        standard:[{required: true, message: '此项必填', trigger: 'blur'},],
      },

      goodsLineList:[],

      dialogVisibleImprot2:false,//批量导入弹窗
      EditLoading2:false,//批量导入提交按钮loadin
      showFial2:false,//批量导入失败
      msg2:'',//上传文件信息
      uploadLoading:false,
      da:[],
      file:null,
      showClose2:false,
      url:'',
      token:'',
      userOptionList2:[]

    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId',
      'isMange',
    ]),
    growthAnalysisTeam(){
      if(this.roles.indexOf("growthAnalysisTeam") != -1){
        return true
      }else{
        return false
      }
    },
    growthAnalysisAll(){
      if(this.roles.indexOf("growthAnalysisAll") != -1){
        return true
      }else{
        return false
      }
    },
    benchmark(){
      if(this.roles.indexOf("benchmark") != -1){
        return true
      }else{
        return false
      }
    },
    additional(){
      if(this.roles.indexOf("additional") != -1){
        return true
      }else{
        return false
      }
    },
  },
  created() {
    this.getUserOptionList();
    this.getUserOptionList2();
    this.getCustomerSettingList();
    this.getList();
    this.getList4();
    this.getList5();
    this.token = getToken();
    this.url = '/api/user/standardDownload?token=' + this.token;
    // this.getList2();
  },
  filters: {



  },
  methods:{
    //导入excel
    importfxx(obj) {
      let _this = this;
      this.uploadLoading = true;
      let inputDOM = this.$refs.inputer;
      // 通过DOM取文件数据
      this.file = event.currentTarget.files[0];
      var rABS = false; //是否将文件读取为二进制字符串
      var f = this.file;
      var reader = new FileReader();
      //if (!FileReader.prototype.readAsBinaryString) {
      FileReader.prototype.readAsBinaryString = function(f) {
        var binary = "";
        var rABS = false; //是否将文件读取为二进制字符串
        var pt = this;
        var wb; //读取完成的数据
        var outdata;
        var reader = new FileReader();
        reader.onload = function(e) {
          var bytes = new Uint8Array(reader.result);
          var length = bytes.byteLength;
          for(var i = 0; i < length; i++) {
            binary += String.fromCharCode(bytes[i]);
          }
          var XLSX = require('xlsx');
          if(rABS) {
            wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
              type: 'base64'
            });
          } else {
            wb = XLSX.read(binary, {
              type: 'binary'
            });
          }
          outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);//outdata就是你想要的东西
          _this.da = [...outdata];
          console.log("da",_this.da)
          let arr = [];

          let para = {
            withList: arr
          };
          _this.$message({
            message: '上传成功，请点击提交',
            type: 'success'
          });
          _this.uploadLoading = false;
        };
        reader.readAsArrayBuffer(f);
      };
      if(rABS) {
        reader.readAsArrayBuffer(f);
      } else {
        reader.readAsBinaryString(f);
      }
    },
    //显示导入弹窗
    showImport2(){
      this.showFial2 = false;
      this.EditLoading2 = false;
      this.uploadLoading = false;
      this.msg2 = '';
      this.dialogVisibleImprot2 = true;
    },
    //关闭导入弹窗
    beforeCloseEditPrice2(){
      $("#upload").val('');
      this.da = [];
      this.msg2 = '';
      this.dialogVisibleImprot2 = false;
    },


    //提交导入
    handleEditPriceConfirm2(){
      if (this.da.length == 0){
        this.$message({
          message: '上传数据为空',
          type: 'warning'
        });
        return false;
      }
      this.msg2 = '后台处理中，请耐心等待……';
      this.showFial2 = false;
      this.EditLoading2 = true;
      this.showClose2 = false;
      importStandard({list:this.da}).then((res)=>{
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.msg2 = '修改成功';
        this.EditLoading2 = false;
        this.dialogVisible2 = false;
        this.showClose2 = true;
        this.da = [];
        this.dialogVisibleImprot2 = false;
        $("#upload").val('');
        this.getList4();
      }).catch((err)=>{
        this.msg2 = err.msg;
        this.showFial2 = true;
        this.EditLoading2 = false;
        $("#upload").val('');
        this.showClose2 = true;
      })
    },

    //获取客户配置
    getCustomerSettingList(){
      getCustomerSetting().then((res)=>{
        res.forEach((el)=>{
          if(el.cdtCode == 'goods_line'){
            this.goodsLineList = el.data
          }
        });
      })
    },


    showPop(type,item){
      this.dialogVisible = true;
      this.form = JSON.parse(JSON.stringify(defaultForm));
      if(type == 'edit'){
        this.form = JSON.parse(JSON.stringify(item));
      }
    },
    //关闭交接量设置
    handleClose(){
      this.dialogVisible = false;
    },
    //确认交接量设置
    handleConfirm(){
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          let data = JSON.parse(JSON.stringify(this.form));
          addAdditional(data).then((res)=>{
            this.btnLoading = false;
            this.handleClose();
            this.getList5();
          }).catch(()=>{
            this.btnLoading = false;
          })
        }
      })
    },

    delItem(item){
      this.$confirm('确认删除交接量？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delAdditional({usaId:item.usaId}).then(()=>{
          this.getList5()
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },


    //显示基准量
    showPop2(type,item){
      this.dialogVisible2 = true;
      this.form2 = JSON.parse(JSON.stringify(defaultForm2));
      if(type == 'edit'){
        this.form2 = JSON.parse(JSON.stringify(item));
      }
    },
    //关闭基准量设置
    handleClose2(){
      this.dialogVisible2 = false;
    },
    //确认基准量设置
    handleConfirm2(){
      this.$refs.form2.validate((valid) => {
        if (valid) {
          this.btnLoading2 = true;
          let data = JSON.parse(JSON.stringify(this.form2));
          addStandard(data).then((res)=>{
            this.btnLoading2 = false;
            this.handleClose2();
            this.getList4();
          }).catch(()=>{
            this.btnLoading2 = false;
          })
        }
      })
    },


    //获取员工下拉选项
    getUserOptionList(){
      getDepartmentUser({type:'all'}).then((res)=>{
        this.userOptionList = res;
      })
    },

    //获取员工下拉选项部门
    getUserOptionList2(){
      getDepartmentUser({type:'department'}).then((res)=>{
        this.userOptionList2 = res;
      })
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    //获取列表
    getList() {
      this.listLoading = true;
      let pa = JSON.parse(JSON.stringify(this.listQuery))
      pa.userIds = [this.userId]
      getTargetVolumeList(pa).then(response => {
        this.tableData = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },


    handleSizeChange2(val){
      this.listQuery2.pageNum = 1;
      this.listQuery2.pageSize = val;
      this.getList2();
    },
    handleCurrentChange2(val){
      this.listQuery2.pageNum = val;
      this.getList2();
    },
    handleSearchList2(){
      this.listQuery2.pageNum = 1;
      this.getList2();
    },

    //获取列表
    getList2() {
      this.listLoading2 = true;
      let pa = JSON.parse(JSON.stringify(this.listQuery2))
      getTargetVolumeList(pa).then(response => {
        this.tableData2 = response.list;
        this.count2 = response.count;
        this.listLoading2 = false;
      }).catch(()=>{
        this.listLoading2 = false;
      });
    },

    handleSizeChange3(val){
      this.listQuery3.pageNum = 1;
      this.listQuery3.pageSize = val;
      this.getList3();
    },
    handleCurrentChange3(val){
      this.listQuery3.pageNum = val;
      this.getList3();
    },

    handleSearchList3(){
      this.listQuery3.pageNum = 1;
      this.getList3();
    },
    //获取列表
    getList3() {
      this.listLoading3 = true;
      let pa = JSON.parse(JSON.stringify(this.listQuery3))
      getTargetVolumeList(pa).then(response => {
        this.tableData3 = response.list;
        this.count3 = response.count;
        this.listLoading3 = false;
      }).catch(()=>{
        this.listLoading3 = false;
      });
    },




    handleSizeChange4(val){
      this.listQuery4.pageNum = 1;
      this.listQuery4.pageSize = val;
      this.getList4();
    },
    handleCurrentChange4(val){
      this.listQuery4.pageNum = val;
      this.getList4();
    },

    handleSearchList4(){
      this.listQuery4.pageNum = 1;
      this.getList4();
    },

    //获取列表
    getList4() {
      this.listLoading4 = true;
      let pa = JSON.parse(JSON.stringify(this.listQuery4))
      getStandardList(pa).then(response => {
        this.tableData4 = response.list;
        this.count4 = response.count;
        this.listLoading4 = false;
      }).catch(()=>{
        this.listLoading4 = false;
      });
    },

    handleSizeChange5(val){
      this.listQuery5.pageNum = 1;
      this.listQuery5.pageSize = val;
      this.getList5();
    },
    handleCurrentChange5(val){
      this.listQuery5.pageNum = val;
      this.getList5();
    },

    handleSearchList5(){
      this.listQuery5.pageNum = 1;
      this.getList5();
    },

    //获取列表
    getList5() {
      this.listLoading5 = true;
      let pa = JSON.parse(JSON.stringify(this.listQuery5))
      getAdditionalList(pa).then(response => {
        this.tableData5 = response.list;
        this.count5 = response.count;
        this.listLoading5 = false;
      }).catch(()=>{
        this.listLoading5 = false;
      });
    },


  },
}
</script>

<style scoped lang="scss">
.avatar-uploader{
  margin-bottom:10px;
  display: block;
}
.upload-div{
  text-align: center;
  position:relative;
  #upload{

    opacity: 0;
    position: absolute;
    z-index: 1;
    width:154px;
    height:40px
  }
}
</style>
